<?
require("page.inc");
require("database.inc");
$inserbook=new page2;
$isbn=trim($_POST['isbn']);
$title=trim($_POST['title']);
$author=trim($_POST['author']);
$price=trim($_POST['price']);
if(!get_magic_quotes_gpc()){
	$isbn=addslashes($isbn);	
	$title=addslashes($title);	
	$price=addslashes($price);	
	$author=addslashes($author);	
	}
if(!preg_match("/^[0-9]-[0-9]{3}-[0-9]{5}-[0-9]$/",$isbn)){
	$inserbook->display();
	echo "$isbn ISBN Format Wrong!";
	$inserbook->displayfooter();
	exit;
	}
if(!is_numeric($price)){
	$inserbook->display();
	echo "$price Price Format Wrong!";
	$inserbook->displayfooter();
	exit;
	}
@$con=new mysqli($lu_host,$lu_user,$lu_psw,$lu_db);
//或者上面两行写成 $con=new sqli('localhost','lustudy_web','123456',';lustudy')
if(mysqli_connect_error()){
	$inserbook->display();
	echo "Databasa connect error!Please Try Again Later.";
	$inserbook->displayfooter();
	exit;
	}
$con->select_db($lu_db);
//此处应当加一个判断

$insertsql="insert into books values ('".$isbn."','".$author."','".$title."','".$price."')";
//echo $insertsql;
$result1=$con->query($insertsql);
$inserbook->display();
if(!$result1){echo "插入失败，有重复值。";$inserbook->displayfooter();exit;}
echo "数据插入成功！<br />您插入的数据为：<br />";
$selectstr="select title,author,price from books where isbn='$isbn'";
//echo $selectstr;
$result2=$con->query($selectstr);
//此处加一个判断“抱歉无法获得您刚才插入的数据”
$row=$result2->fetch_assoc();
echo "TiTle:《".$row['title']."》<br />";
echo "ISBN:".$isbn."<br />";
echo "Author:".$row['author']."<br />";
echo "Price:".$row['price']."<br />";
$inserbook->displayfooter();
?>